package com.sobot.finance.poc.web.util;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.LineIter;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.setting.dialect.Props;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.sobot.finance.poc.web.service.TaskService;
import lombok.Data;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author baiyp
 */
@Slf4j
public class Test {

    public static void main(String[] args) {

        Gson gson = new Gson();
        final LineIter liner_s = new LineIter(ResourceUtil.getUtf8Reader("json/p1.properties"));

        Set<String> set_s = Sets.newHashSet();
        for (String line : liner_s) {
            if (StrUtil.isBlank(line)) {
                continue;
            }
            if (StrUtil.startWith(line, "#")) {
                continue;
            }
            List<String> split = StrUtil.split(line, "=");
            if (CollUtil.isEmpty(split) || split.size() != 2) {
                continue;
            }

            set_s.add(split.get(0));
        }

        final LineIter liner_v = new LineIter(ResourceUtil.getUtf8Reader("json/p2.properties"));

        Set<String> set_v = Sets.newHashSet();
        for (String line : liner_v) {
            if (StrUtil.isBlank(line)) {
                continue;
            }
            if (StrUtil.startWith(line, "#")) {
                continue;
            }
            List<String> split = StrUtil.split(line, "=");
            if (CollUtil.isEmpty(split) || split.size() != 2) {
                continue;
            }

            set_v.add(split.get(0));
        }


        List<String> strings = CollUtil.subtractToList(set_v, set_s);
        System.out.println(strings.size());
        strings.forEach(System.out::println);

        // int i = Integer.parseInt("1647253138000");

        /*String cdp = ResourceUtil.readUtf8Str("json/cdp.txt");
        String zhi = ResourceUtil.readUtf8Str("json/zhi.txt");

        Set<String> cList = Sets.newHashSet(StrUtil.split(cdp, StrUtil.COMMA));
        Set<String> zList = Sets.newHashSet(StrUtil.split(zhi, StrUtil.COMMA));

        log.info("[cList-size]: {}", cList.size());
        log.info("[zList-size]: {}", zList.size());

        List<String> cOnly = CollUtil.subtractToList(cList, zList);
        List<String> zOnly = CollUtil.subtractToList(zList, cList);
        log.info("[cOnly-size]: {}", cOnly.size());
        log.info("[zOnly-size]: {}", zOnly.size());

        log.info("[cOnly]: {}", cOnly);
        log.info("[zOnly]: {}", zOnly);*/

        /*String json = ResourceUtil.readUtf8Str("json/a.json");
        Res res = new Gson().fromJson(json, Res.class);

        if (res != null && res.isSuccess()) {
            Map<String, Object> item = res.getItem();
            log.info(item.toString());
        }*/

        /*Map<String, Object> map = mkResultSet("13321610188");
        log.info(map.toString());*/
    }

    private static Map<String, Object> mkResultSet(String tel) {
        log.info("[查询MK客户数据-开始]");
        Gson gson = new Gson();
        Map<String, Object> map = Maps.newHashMap();
        try {
            String url = StrUtil.format("http://customerservice.michaelkors.cn/basic/getMkUser/4?phone={}", tel);
            // 请求
            String result = HttpRequest.get(url)
                    .timeout(20_000)
                    .execute()
                    .body();

            log.info("[result]: " +  gson.toJson(result));

            Res res = gson.fromJson(result, Res.class);

            if (res != null && res.isSuccess()) {
                map = res.getItem();
            }
        } catch (Exception e) {
            log.error("[异常]: ", e);
        }
        log.info("[查询MK客户数据-结束]");
        return map;
    }

    @Data
    @ToString
    public static class Res {
        private String retCode;
        private String retMsg;
        private Map<String, Object> item;
        private List<Map<String, Object>> items;

        public boolean isSuccess() {
            return StrUtil.equals("000000", retCode);
        }
    }

    @Data
    @ToString
    public static class Top {
        private String consumerId;
    }
}
